package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.dto.RoleDto;
import com.itheima.ydd.entity.RoleMenu;
import com.itheima.ydd.mapper.RoleMenuMapper;
import com.itheima.ydd.service.MenuService;
import com.itheima.ydd.service.RoleMenuService;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {
    @Override
    public void updateRoleMenu(RoleDto roleDto) {
        // 先根据roleId删除
        LambdaQueryWrapper<RoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RoleMenu::getRoleId, roleDto.getId());
        super.remove(queryWrapper);
        // 按集合存储
        List<RoleMenu> roleMenus = new LinkedList<>();
        // List<RoleMenu> roleMenus = new ArrayList<>(roleDto.getMenuIds().size());

//        for (Integer menuId : roleDto.getMenuIds()) {
//            RoleMenu roleMenu = new RoleMenu();
//            roleMenu.setRoleId(roleDto.getId());
//            roleMenu.setMenuId(menuId.toString());
//            roleMenus.add(roleMenu);
//        }
//        super.saveBatch(roleMenus);

    }
}
